package com.skytech.tax.customsdatawarehouse.singlewindow.processtrade.manual.domain.dao;

import com.skytech.tax.customsdatawarehouse.singlewindow.processtrade.manual.domain.entity.ManualGoodsImg;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Lianhong
 * @since 2021/11/11
 */
@Repository
public class ManualGoodsImgDao {

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    private String deleteManualGoodsExgSql = "DELETE FROM sw_manual_goods_img WHERE seqNo=:seqNo and gdsSeqno in (:gseqNos)";

    public void removeBySeqNoAndGdsSeqnoIn(String seqNo, List<String> gdsSeqno) {
        Map<String, Object> params = new HashMap<>();
        params.put("seqNo", seqNo);
        params.put("gdsSeqno", gdsSeqno);
        namedParameterJdbcTemplate.update(this.deleteManualGoodsExgSql, params);
    }

    private String insertManualGoodsExgSql = "INSERT INTO sw_manual_goods_img (seqNo, gdsSeqno, img, storageTime)" +
            " VALUES (:seqNo, :gdsSeqno, :img, :storageTime)";

    public void save(List<ManualGoodsImg> imgList) {
        SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(imgList);
        namedParameterJdbcTemplate.batchUpdate(insertManualGoodsExgSql, batch);
    }
}


